package com.wyd.studentboot.controller;

import com.wyd.studentboot.bean.Msg;
import com.wyd.studentboot.bean.SignInLag;
import com.wyd.studentboot.bean.StudentBean;
import com.wyd.studentboot.bean.UserBean;
import com.wyd.studentboot.service.SignInLagService;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class SignInLagController {
    @Resource
    private SignInLagService service;
    /**
     * 时段签到(签到时间6-8pm)
     * @return
     */
    @RequestMapping(value = "/sign/lag")
    public Msg lag(HttpServletRequest request){
        //接收用户数据
        UserBean user = (UserBean) request.getSession().getAttribute("user");
        if(user==null) return new Msg(0,"抱歉，检测到您未登录！");
        //0签到时间段设置错误1未到签到时间2签到已结束3可签到4签到成功5签到失败
        return service.add(new SignInLag(user.getStudent_id(), 1));
    }
    /**
     * 签到历史数据
     * @param request
     * @return
     */
    @RequestMapping(value = "/sign/lag/history")
    public List<SignInLag> history(HttpServletRequest request){
        //获取用户信息
        UserBean user = (UserBean) request.getSession().getAttribute("user");
        if(user==null)return null;
        List<SignInLag> signs = service.history(user.getStudent_id());
        return signs;
    }
}
